home *** CD-ROM | disk | FTP | other *** search
- This directory contains the sample source code for a very simple compiler
- called SCC. This compiler is not very practical, but it illustrates the
- basics of how a compiler can translate a script source code into bytecode
- stream.
-
- In order to compile this sample program, you will need working copies of
- GNU Bison and GNU Flex (Flex is a lexical analyzer commonly used in
- conjunction with Bison). Since Microsoft Visual C++ 6.0 was the target
- platform for this source code, I suggest installing the Cygwin utilities.
- Cygwin is a UNIX environment for Windows, and it contains working copies
- of Bison & Flex.
-
- http://www.cygwin.com/
-
- Once you have Cygwin installed and in your path, you should be able to
- build this example by simply running nmake. The sample program will be
- generated in Debug\scc.exe.
-
- Executing this program is pretty straight forward. Create a text file
- that contains the source code you want to compile, and pass this file as
- an argument to scc. For example:
-
- scc TestScript.scc
-
- The program will write to the screen the parse tree node, and the
- generated bytecode stream will be written to out.bin.
-
- The language that the compiler understands is very simple. The more
- complicated language constructs where omitted in order to help illustrate
- the basic code generation techniques. Source scripts can consist of any
- number of lines of basic math instructions. Only integers are supported,
- and each line must be terminated with a semi-color. The following are
- examples of valid input for the script:
-
- 10-9*3;
- 4+5;
- 10/3-5*(2/10);
-
- A small sample script is included in the file sample.scc.
-